package com.cmc.cloud.cmclink.doc.rpcservice.impl;

import com.alibaba.fastjson.JSON;
import com.cmc.cloud.cmclink.doc.rpcservice.RateTransfer;
import com.cmc.cloud.cmclink.mkt.dto.loc.CalLocReqVo;
import com.cmc.cloud.cmclink.mkt.dto.loc.CalLocRespVo;
import com.cmc.cloud.cmclink.mkt.dto.rate.CalFrtReqVo;
import com.cmc.cloud.cmclink.mkt.dto.rate.CalFrtRespVo;
import com.cmc.cloud.cmclink.mkt.rate.RateRpcApi;
import com.cmes.framework.common.pojo.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 营销-费率 实现类
 *
 * @author dev89
 * @date 2025/08/14 10:53
 **/
@Service
@Validated
@Slf4j
public class RateTransferImpl implements RateTransfer {
    @Resource
    private RateRpcApi rateRpcApi;

    @Override
    public CalFrtRespVo calForecastFreight(CalFrtReqVo calFrtReqVo) {
        log.info("rate calculate start:{}, queryId:{}", LocalDateTime.now(), calFrtReqVo.getQueryId());
        CommonResult<CalFrtRespVo> commonResult = rateRpcApi.calForecastFreight(calFrtReqVo);
        log.info("ptu calculate start:{}, queryId:{}, commonResult_code: {}, commonResult_msg:{}", LocalDateTime.now(),
            calFrtReqVo.getQueryId(), commonResult.getCode(), commonResult.getMsg());
        return commonResult.getCheckedData();
    }

    @Override
    public CommonResult<List<CalLocRespVo>> batchCalPorLocal(List<CalLocReqVo> regVos) {
        log.info("calBatchCalPorLocal start:{}", LocalDateTime.now());
        System.out.println("输出请求日志");
        System.out.println(JSON.toJSONString(regVos));
        CommonResult<List<CalLocRespVo>> commonResult = rateRpcApi.batchCalPorLocal(regVos);
        log.info("calBatchCalPorLocal end:{}", LocalDateTime.now());
        return commonResult;
    }

    @Override
    public  CommonResult<List<CalLocRespVo>> batchCalDesLocal(List<CalLocReqVo> regVos) {
        log.info("calBatchCalPorLocal start:{}", LocalDateTime.now());
        CommonResult<List<CalLocRespVo>> commonResult = rateRpcApi.batchCalDesLocal(regVos);
        log.info("calBatchCalPorLocal end:{}", LocalDateTime.now());
        return commonResult;
    }


}
